<template>
  <div class="PointsEdit">
    <el-dialog
      custom-class="el-dialog-redefine"
      v-bind="$attrs"
      title="点位设置"
      :visible.sync="dialogVisible"
      :show-close="showClose"
      @open="dialogOpen"
    >
      <div class="outside-border">
        <div class="data-area">
          <el-tabs class="el-tabs-redefine" v-model="editableTabsValue" type="border-card">
            <el-tab-pane label="基础属性" name="first">
              <div class="tab-custom-area">
                <div class="conditions-area">
                  <el-form
                    ref="pointForm"
                    :model="pointForm"
                    :rules="pointFormRules"
                    size="mini"
                    label-width="150px"
                  >
                    <el-row>
                      <el-col :span="8">
                        <el-form-item size="mini" label="变电站:" prop="substationId">
                          <el-select
                            size="mini"
                            clearable
                            placeholder="请选择"
                            v-model="pointForm.substationId"
                            @change="handleSubstationChange"
                          >
                            <el-option
                              v-for="item in substationList"
                              :key="item.id"
                              :label="item.name"
                              :value="item.id"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="区域:" prop="areaId">
                          <el-select
                            size="mini"
                            clearable
                            placeholder="请选择"
                            v-model="pointForm.areaId"
                            @change="handleAreaChange"
                          >
                            <el-option
                              v-for="item in areaList"
                              :key="item.id"
                              :label="item.name"
                              :value="item.id"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="间隔:" prop="intervalId">
                          <el-select
                            size="mini"
                            clearable
                            placeholder="请选择"
                            v-model="pointForm.intervalId"
                            @change="handleIntervalChange"
                          >
                            <el-option
                              v-for="item in intervalList"
                              :key="item.id"
                              :label="item.name"
                              :value="item.id"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="8">
                        <el-form-item size="mini" label="小类设备:" prop="subclassDeviceId">
                          <el-select
                            size="mini"
                            clearable
                            placeholder="请选择"
                            v-model="pointForm.subclassDeviceId"
                            @change="handleSubclassDeviceChange"
                          >
                            <el-option
                              v-for="item in subclassDeviceList"
                              :key="item.id"
                              :label="item.name"
                              :value="item.id"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="设备:" prop="deviceId">
                          <el-select
                            size="mini"
                            clearable
                            placeholder="请选择"
                            v-model="pointForm.deviceId"
                            @change="handleDeviceChange"
                          >
                            <el-option
                              v-for="item in deviceList"
                              :key="item.id"
                              :label="item.name"
                              :value="item.id"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="8">
                        <el-form-item size="mini" label="名称:" prop="name">
                          <el-input size="mini" v-model="pointForm.name" maxlength="15"></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="显示名称:" prop="displayName">
                          <el-input size="mini" v-model="pointForm.displayName" maxlength="15"></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="8">
                        <el-form-item size="mini" label="识别类型:" prop="reconTypeId">
                          <el-select
                            size="mini"
                            clearable
                            placeholder="请选择"
                            v-model="pointForm.reconTypeId"
                          >
                            <el-option
                              v-for="item in recognitionTypeList"
                              :key="item.id"
                              :label="item.name"
                              :value="item.id"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="表计类型:" prop="meterTypeId">
                          <el-select
                            size="mini"
                            clearable
                            placeholder="请选择"
                            v-model="pointForm.meterTypeId"
                          >
                            <el-option
                              v-for="item in meterTypeList"
                              :key="item.id"
                              :label="item.name"
                              :value="item.id"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="设备外观类型:" prop="faceTypeId">
                          <el-select
                            size="mini"
                            clearable
                            placeholder="请选择"
                            v-model="pointForm.faceTypeId"
                          >
                            <el-option
                              v-for="item in deviceAppearanceTypeList"
                              :key="item.id"
                              :label="item.name"
                              :value="item.id"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="8">
                        <el-form-item size="mini" label="发热类型:" prop="hotTypeId">
                          <el-select
                            size="mini"
                            clearable
                            placeholder="请选择"
                            v-model="pointForm.hotTypeId"
                          >
                            <el-option
                              v-for="item in hotTypesList"
                              :key="item.id"
                              :label="item.name"
                              :value="item.id"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="保存类型:" prop="saveTypeId">
                          <el-select
                            size="mini"
                            clearable
                            placeholder="请选择"
                            v-model="pointForm.saveTypeId"
                          >
                            <el-option
                              v-for="item in saveTypesList"
                              :key="item.id"
                              :label="item.name"
                              :value="item.id"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="8">
                        <el-form-item size="mini" label="识别模型:" prop="reconModelId">
                          <el-select
                            size="mini"
                            clearable
                            placeholder="请选择"
                            v-model="pointForm.reconModelSub.reconModelId"
                            @change="handleReconModelChange"
                          >
                            <el-option
                              v-for="item in recognitionModelsList"
                              :key="item.id"
                              :label="item.name"
                              :value="item.id"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="识别子模型:" prop="reconModelSubId">
                          <el-select
                            size="mini"
                            clearable
                            placeholder="请选择"
                            v-model="pointForm.reconModelSubId"
                          >
                            <el-option
                              v-for="item in recognitionSubModelsList"
                              :key="item.id"
                              :label="item.name"
                              :value="item.id"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="8">
                        <el-form-item size="mini" label="可见光宽:" prop="width">
                          <el-input
                            size="mini"
                            v-model="pointForm.pointVisibleLight.width"
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="可见光高:" prop="height">
                          <el-input
                            size="mini"
                            v-model="pointForm.pointVisibleLight.height"
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="8">
                        <el-form-item size="mini" label="观测位:" prop="watchPosId">
                          <el-select
                            size="mini"
                            clearable
                            placeholder="请选择"
                            v-model="pointForm.watchPosId"
                          >
                            <el-option
                              v-for="item in watchPossList"
                              :key="item.id"
                              :label="item.x + ', ' + item.y + ', ' + item.z"
                              :value="item.id"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="nis:" prop="nis">
                          <el-radio-group size="mini" v-model="pointForm.nis">
                            <el-radio :label="0">采集</el-radio>
                            <el-radio :label="1">计算</el-radio>
                          </el-radio-group>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="8">
                        <el-form-item size="mini" label="是否报警:" prop="isAlarm">
                          <el-switch
                            :width="60"
                            active-color="#109CB4"
                            inactive-color="#afafaf"
                            active-text="是"
                            inactive-text="否"
                            :active-value="1"
                            :inactive-value="0"
                            v-model="pointForm.isAlarm"
                          ></el-switch>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="是否展示:" prop="isShow">
                          <el-switch
                            :width="60"
                            active-color="#109CB4"
                            inactive-color="#afafaf"
                            active-text="是"
                            inactive-text="否"
                            :active-value="1"
                            :inactive-value="0"
                            v-model="pointForm.isShow"
                          ></el-switch>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="是否保存:" prop="isSave">
                          <el-switch
                            :width="60"
                            active-color="#109CB4"
                            inactive-color="#afafaf"
                            active-text="是"
                            inactive-text="否"
                            :active-value="1"
                            :inactive-value="0"
                            v-model="pointForm.isSave"
                          ></el-switch>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="8">
                        <el-form-item size="mini" label="是否启用:" prop="isUse">
                          <el-switch
                            :width="60"
                            active-color="#109CB4"
                            inactive-color="#afafaf"
                            active-text="是"
                            inactive-text="否"
                            :active-value="1"
                            :inactive-value="0"
                            v-model="pointForm.isUse"
                          ></el-switch>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="8">
                        <el-form-item size="mini" label="单位:" prop="unit">
                          <el-input size="mini" v-model="pointForm.unit" maxlength="15"></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="系数:" prop="coef">
                          <el-input
                            size="mini"
                            v-model="pointForm.coef"
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="默认值:" prop="defaultValue">
                          <el-input
                            size="mini"
                            v-model="pointForm.defaultValue"
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="8">
                        <el-form-item size="mini" label="x坐标:" prop="x">
                          <el-input
                            size="mini"
                            v-model="pointForm.x"
                            oninput="value=value.replace(/[^0-9.-]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="y坐标:" prop="y">
                          <el-input
                            size="mini"
                            v-model="pointForm.y"
                            oninput="value=value.replace(/[^0-9.-]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="z坐标:" prop="z">
                          <el-input
                            size="mini"
                            v-model="pointForm.z"
                            oninput="value=value.replace(/[^0-9.-]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="8">
                        <el-form-item size="mini" label="正向水平角预置量:" prop="fHAngle">
                          <el-input
                            size="mini"
                            v-model="pointForm.fHAngle"
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="正向俯仰角预置量:" prop="fPAngle">
                          <el-input
                            size="mini"
                            v-model="pointForm.fPAngle"
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="正向倍率预置量:" prop="fMult">
                          <el-input
                            size="mini"
                            v-model="pointForm.fMult"
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="8">
                        <el-form-item size="mini" label="反向水平角预置量:" prop="bHAngle">
                          <el-input
                            size="mini"
                            v-model="pointForm.bHAngle"
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="反向俯仰角预置量:" prop="bPAngle">
                          <el-input
                            size="mini"
                            v-model="pointForm.bPAngle"
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="反向倍率预置量:" prop="bMult">
                          <el-input
                            size="mini"
                            v-model="pointForm.bMult"
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="8">
                        <el-form-item size="mini" label="正向预置位号:" prop="fPresetNo">
                          <el-input
                            size="mini"
                            v-model="pointForm.fPresetNo"
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item size="mini" label="反向预置位号:" prop="bPresetNo">
                          <el-input
                            size="mini"
                            v-model="pointForm.bPresetNo"
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="24">
                        <el-form-item
                          label-width="410px"
                          size="mini"
                          label="针对相机对准是否计算对准还是直接调用预制值对准的开关量:"
                          prop="calcOnOff"
                        >
                          <el-select
                            size="mini"
                            clearable
                            placeholder="请选择"
                            v-model="pointForm.calcOnOff"
                          >
                            <el-option
                              v-for="item in calcOnOffList"
                              :key="item.id"
                              :label="item.name"
                              :value="item.id"
                            ></el-option>
                          </el-select>
                          <!-- <el-switch
                            :width="60"
                            active-color="#109CB4"
                            inactive-color="#afafaf"
                            active-text="开"
                            inactive-text="关"
                            :active-value="1"
                            :inactive-value="0"
                            v-model="pointForm.calcOnOff"
                          ></el-switch>-->
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </el-form>
                </div>
              </div>
            </el-tab-pane>
            <el-tab-pane label="表计属性" name="second" v-if="pointForm.reconTypeId === 1">
              <div class="tab-custom-area">
                <div class="conditions-area">
                  <el-form
                    ref="meterForm"
                    :model="meterForm"
                    :rules="meterFormRules"
                    size="mini"
                    label-width="150px"
                  >
                    <el-row>
                      <el-col :span="12">
                        <el-form-item size="mini" label="起始角度 :" prop="angleMin">
                          <el-input
                            size="mini"
                            v-model="meterForm.angleMin"
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item size="mini" label="截止角度:" prop="angleMax">
                          <el-input
                            size="mini"
                            v-model="meterForm.angleMax"
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="12">
                        <el-form-item size="mini" label="量程下限:" prop="rangeMin">
                          <el-input
                            size="mini"
                            v-model="meterForm.rangeMin"
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item size="mini" label="量程上限:" prop="rangeMax">
                          <el-input
                            size="mini"
                            v-model="meterForm.rangeMax"
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="12">
                        <el-form-item size="mini" label="反向水平角预置量:" prop="direction">
                          <el-input
                            size="mini"
                            v-model="meterForm.direction "
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item size="mini" label="反向俯仰角预置量:" prop="offsetValue">
                          <el-input
                            size="mini"
                            v-model="meterForm.offsetValue"
                            oninput="value=value.replace(/[^0-9.]/g,'')"
                            maxlength="15"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </el-form>
                </div>
              </div>
            </el-tab-pane>
          </el-tabs>
        </div>
        <el-button
          size="small"
          style="width: 130px; margin: 10px 0; float: right;"
          @click="saveClick"
        >保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  pointsAdd,
  pointsUpdate,
  pointsDetail,
  reconTypesList,
  meterTypesList,
  faceTypesList,
  hotTypesList,
  saveTypesList,
  watchPossList,
  reconModelsList,
  reconModelSubsList,
  robotParams,
  postOperationLogs
} from "@/api/apiManagement";
import { validatEmpty } from "@/utils/validate";

export default {
  name: "PointsEdit",
  props: {
    showClose: {
      type: Boolean,
      default: true
    },
    data: {
      type: [Array, Object],
      required: true
    },
    tree: {
      type: [Array, Object],
      required: true
    },
    substation: {
      type: [Array, Object],
      required: true
    },
    area: {
      type: [Array, Object],
      required: true
    },
    interval: {
      type: [Array, Object],
      required: true
    },
    subclassDevice: {
      type: [Array, Object],
      required: true
    },
    device: {
      type: [Array, Object],
      required: true
    },
    point: {
      type: [Array, Object],
      required: true
    }
  },
  data() {
    return {
      robot_id: null,
      dialogVisible: false,
      editableTabsValue: "first",
      isEdit: false,
      historyData: {},
      pointForm: {
        substationId: null,
        areaId: null,
        intervalId: null,
        subclassDeviceId: null,
        deviceId: null,
        pointId: null,
        bHAngle: null,
        bMult: null,
        bPAngle: null,
        bPresetNo: null,
        calcOnOff: null,
        coef: null,
        defaultValue: null,
        deviceName: "",
        displayName: "",
        fHAngle: null,
        fMult: null,
        fPAngle: null,
        fPresetNo: null,
        faceTypeId: null,
        hotTypeId: null,
        isAlarm: null,
        isSave: null,
        isShow: null,
        isUse: 1,
        meterTypeId: null,
        name: "",
        nis: null,
        reconModelSubId: null,
        reconTypeId: null,
        saveTypeId: null,
        unit: "",
        watchPosId: null,
        x: null,
        y: null,
        z: null,
        reconModelSub: {
          description: "",
          displayName: "",
          id: null,
          name: "",
          reconModelId: null
        },
        pointVisibleLight: {
          id: null,
          width: null,
          height: null
        },
        pointVisibleLightRequest: {
          id: null,
          width: null,
          height: null
        },
        meterPointInfoRequest: {
          angleMax: null,
          angleMin: null,
          direction: null,
          id: null,
          meterTypeId: null,
          offsetValue: null,
          rangeMax: null,
          rangeMin: null
        }
      },
      pointFormRules: {
        substationId: [
          { required: false, trigger: "blur", message: "请选择变电站" }
        ],
        areaId: [{ required: false, trigger: "blur", message: "请选择区域" }],
        intervalId: [
          { required: false, trigger: "blur", message: "请选择间隔" }
        ],
        subclassDeviceId: [
          { required: false, trigger: "blur", message: "请选择小类设备" }
        ],
        deviceId: [{ required: false, trigger: "blur", message: "请选择设备" }],
        pointId: [{ required: false, trigger: "blur", message: "" }],
        bHAngle: [
          {
            required: false,
            trigger: "blur",
            message: "请输入反向水平角预置量"
          }
        ],
        bMult: [
          { required: false, trigger: "blur", message: "请输入反向倍率预置量" }
        ],
        bPAngle: [
          {
            required: false,
            trigger: "blur",
            message: "请输入反向俯仰角预置量 "
          }
        ],
        bPresetNo: [
          { required: false, trigger: "blur", message: "请输入反向预置位号" }
        ],
        calcOnOff: [
          {
            required: false,
            trigger: "blur",
            message:
              "请选择针对相机对准是否计算对准还是直接调用预制值对准的开关量"
          }
        ],
        coef: [{ required: false, trigger: "blur", message: "请输入系数" }],
        defaultValue: [
          { required: false, trigger: "blur", message: "请输入默认值" }
        ],
        deviceName: [
          { required: false, trigger: "blur", message: "请输入设备双重命名" }
        ],
        displayName: [
          { required: false, trigger: "blur", message: "请输入点位显示名称" }
        ],
        fHAngle: [
          {
            required: false,
            trigger: "blur",
            message: "请输入正向水平角预置量"
          }
        ],
        fMult: [
          { required: false, trigger: "blur", message: "请输入正向倍率预置量" }
        ],
        fPAngle: [
          {
            required: false,
            trigger: "blur",
            message: "请输入正向俯仰角预置量"
          }
        ],
        fPresetNo: [
          { required: false, trigger: "blur", message: "请输入正向预置位号" }
        ],
        faceTypeId: [
          { required: false, trigger: "blur", message: "请选择外观类型" }
        ],
        hotTypeId: [
          { required: false, trigger: "blur", message: "请选择发热类型" }
        ],
        isAlarm: [
          { required: false, trigger: "blur", message: "请选择是否报警" }
        ],
        isSave: [
          { required: false, trigger: "blur", message: "请选择是否保存" }
        ],
        isShow: [
          {
            required: false,
            trigger: "blur",
            message: "请选择前端是否提示报警"
          }
        ],
        isUse: [
          { required: false, trigger: "blur", message: "请选择是否启用" }
        ],
        meterTypeId: [
          { required: false, trigger: "blur", message: "请选择表计类型" }
        ],
        name: [{ required: false, trigger: "blur", message: "请输入名字" }],
        nis: [
          { required: false, trigger: "blur", message: "请选择采集或计算" }
        ],
        reconTypeId: [
          { required: false, trigger: "blur", message: "请选择识别类型" }
        ],
        saveTypeId: [
          { required: false, trigger: "blur", message: "请选择保存类型" }
        ],
        unit: [{ required: false, trigger: "blur", message: "请输入单位" }],
        watchPosId: [
          { required: false, trigger: "blur", message: "请选择观测位" }
        ],
        x: [{ required: false, trigger: "blur", message: "请输入X坐标" }],
        y: [{ required: false, trigger: "blur", message: "请输入Y坐标" }],
        z: [{ required: false, trigger: "blur", message: "请输入Z坐标" }]
      },
      calcOnOffList: [
        {
          id: 0,
          name: "自动校准"
        },
        {
          id: 1,
          name: "预置值"
        },
        {
          id: 2,
          name: "预置位"
        }
      ],
      meterForm: {
        angleMax: null,
        angleMin: null,
        direction: null,
        id: null,
        meterTypeId: null,
        offsetValue: null,
        rangeMax: null,
        rangeMin: null
      },
      meterFormRules: {},
      //
      // substationList: [],
      // areaList: [],
      // intervalList: [],
      // deviceList: [],
      recognitionTypeList: [],
      meterTypeList: [],
      deviceAppearanceTypeList: [],
      hotTypesList: [],
      saveTypesList: [],
      recognitionModelsList: [],
      // recognitionSubModelsList: [],
      watchPossList: [],
      rosObj: {
        ip: "",
        port: ""
      }
    };
  },
  computed: {
    substationList: function() {
      if (this.tree) {
        return this.tree;
      } else {
        return [];
      }
    },
    areaList: function() {
      if (this.substationList) {
        for (var i = 0, len = this.substationList.length; i < len; i++) {
          if (this.substationList[i].id === this.pointForm.substationId) {
            return this.substationList[i].children;
          }
        }
      }
    },
    intervalList: function() {
      if (this.areaList) {
        for (var i = 0, len = this.areaList.length; i < len; i++) {
          if (this.areaList[i].id === this.pointForm.areaId) {
            return this.areaList[i].children;
          }
        }
      }
    },
    subclassDeviceList: function() {
      if (this.intervalList) {
        for (var i = 0, len = this.intervalList.length; i < len; i++) {
          if (this.intervalList[i].id === this.pointForm.intervalId) {
            return this.intervalList[i].children;
          }
        }
      }
    },
    deviceList: function() {
      if (this.subclassDeviceList) {
        for (var i = 0, len = this.subclassDeviceList.length; i < len; i++) {
          if (
            this.subclassDeviceList[i].id === this.pointForm.subclassDeviceId
          ) {
            return this.subclassDeviceList[i].children;
          }
        }
      }
    },
    recognitionSubModelsList: function() {
      if (this.recognitionModelsList) {
        for (var i = 0, len = this.recognitionModelsList.length; i < len; i++) {
          if (
            this.recognitionModelsList[i].id ===
            this.pointForm.reconModelSub.reconModelId
          ) {
            return this.recognitionModelsList[i].reconModelSubs;
          }
        }
      }
    }
  },
  created() {},
  mounted() {
  },
  methods: {
    isShowDia(isVisible, bEdit) {
      let self = this;
      self.dialogVisible = isVisible;
      self.isEdit = bEdit;
    },
    dialogOpen() {
      this.robot_id = localStorage.getItem("ydRobot_id");
      this.getRobotParams({
        page: 1,
        size: 0,
        robotId: this.robot_id,
        type: 3
      });
      if (this.isEdit) {
        if (this.data && this.data.point && this.data.point.id) {
          this.getPointsDetail();
        }
      } else {
        for (var item in this.pointForm) {
          this.pointForm[item] = null;
        }
        if (this.pointForm.reconModelSub) {
          //
        } else {
          this.pointForm.reconModelSub = {
            description: "",
            displayName: "",
            id: null,
            name: "",
            reconModelId: null
          };
        }
        if (this.pointForm.pointVisibleLight) {
          //
        } else {
          this.pointForm.pointVisibleLight = {
            id: null,
            width: null,
            height: null
          };
        }
        this.meterForm = {
          angleMax: null,
          angleMin: null,
          direction: null,
          id: null,
          meterTypeId: null,
          offsetValue: null,
          rangeMax: null,
          rangeMin: null
        };
      }
      //
      if (this.substation) {
        this.pointForm.substationId = this.substation.id;
      }
      if (this.area) {
        this.pointForm.areaId = this.area.id;
      }
      if (this.interval) {
        this.pointForm.intervalId = this.interval.id;
      }
      if (this.subclassDevice) {
        this.pointForm.subclassDeviceId = this.subclassDevice.id;
      }
      if (this.device) {
        this.pointForm.deviceId = this.device.id;
      }
      if (this.point) {
        this.pointForm.pointId = this.point.id;
      }
      this.pointForm.isAlarm = 1;
      this.pointForm.isSave = 1;
      this.pointForm.isShow = 1;
      this.pointForm.isUse = 1;
      // 识别类型
      this.getReconTypesList();
      // 表计类型
      this.getMeterTypesList();
      // 设备外观类型
      this.getFaceTypeList();
      // 发热类型
      this.getHotTypesList();
      // 保存类型
      this.getSaveTypesList();
      // 识别模型
      this.getReconModelsList();
      // 观测位
      this.getWatchPossList();
    },
    getPointsDetail() {
      let id = this.data.point.id.substring(6, this.data.point.id.length);
      pointsDetail({}, id)
        .then(response => {
          if (response) {
            for (var item in response) {
              this.pointForm[item] = response[item];
            }
          }
          if (this.pointForm.reconModelSub) {
            //
          } else {
            this.pointForm.reconModelSub = {
              description: "",
              displayName: "",
              id: null,
              name: "",
              reconModelId: null
            };
          }
          if (this.pointForm.pointVisibleLight) {
            //
          } else {
            this.pointForm.pointVisibleLight = {
              id: null,
              width: null,
              height: null
            };
          }
          if (this.pointForm.reconTypeId === 1) {
            if (this.pointForm.meterPointInfo) {
              this.meterForm = this.pointForm.meterPointInfo;
            }
          }
          this.historyData = JSON.parse(JSON.stringify(this.pointForm));
        })
        .catch(() => {});
    },
    // 识别类型
    getReconTypesList() {
      reconTypesList()
        .then(response => {
          if (response.list) {
            this.recognitionTypeList = response.list;
          }
        })
        .catch(() => {});
    },
    // 表计类型
    getMeterTypesList() {
      meterTypesList()
        .then(response => {
          if (response.list) {
            this.meterTypeList = response.list;
          }
        })
        .catch(() => {});
    },
    // 设备外观类型
    getFaceTypeList() {
      faceTypesList()
        .then(response => {
          if (response.list) {
            this.deviceAppearanceTypeList = response.list;
          }
        })
        .catch(() => {});
    },
    // 发热类型
    getHotTypesList() {
      hotTypesList()
        .then(response => {
          if (response.list) {
            this.hotTypesList = response.list;
          }
        })
        .catch(() => {});
    },
    // 保存类型
    getSaveTypesList() {
      saveTypesList()
        .then(response => {
          if (response.list) {
            this.saveTypesList = response.list;
          }
        })
        .catch(() => {});
    },
    // 观测位
    getWatchPossList() {
      watchPossList()
        .then(response => {
          if (response.list) {
            this.watchPossList = response.list;
          }
        })
        .catch(() => {});
    },
    getReconModelsList() {
      reconModelsList({ page: 1, size: 0 })
        .then(response => {
          if (response.list) {
            this.recognitionModelsList = response.list;
          }
        })
        .catch(() => {});
    },
    getReconModelsSubsList() {
      reconModelSubsList({
        page: 1,
        size: 0,
        reconModelId: pointForm.reconModelSub.reconModelId
      })
        .then(response => {
          if (response.list) {
            this.recognitionSubModelsList = response.list;
          }
        })
        .catch(() => {});
    },
    handleSubstationChange(val) {
      this.pointForm.areaId = null;
      this.pointForm.intervalId = null;
      this.pointForm.subclassDeviceId = null;
      this.pointForm.deviceId = null;
    },
    handleAreaChange(val) {
      this.pointForm.intervalId = null;
      this.pointForm.subclassDeviceId = null;
      this.pointForm.deviceId = null;
    },
    handleIntervalChange(val) {
      this.pointForm.subclassDeviceId = null;
      this.pointForm.deviceId = null;
    },
    handleSubclassDeviceChange(val) {
      this.pointForm.deviceId = null;
    },
    handleDeviceChange(val) {
      //
    },
    handleReconModelChange(val) {
      this.pointForm.reconModelSubId = null;
    },
    saveClick() {
      this.$refs["pointForm"].validate(valid => {
        if (valid) {
          // if (this.pointForm.reconTypeId === 1) {
          //   this.pointForm.meterPointInfoRequest = this.meterForm;
          //   this.pointForm.meterPointInfoRequest.meterTypeId = this.pointForm.meterTypeId;
          //   delete this.pointForm.meterPointInfo;
          // } else {
          //   delete this.pointForm.meterPointInfo;
          //   delete this.pointForm.meterPointInfoRequest;
          // }
          // if (this.pointForm.pointVisibleLight) {
          //   this.pointForm.pointVisibleLightRequest = this.pointForm.pointVisibleLight;
          // }
          // delete this.pointForm.pointVisibleLight;
          // delete this.pointForm.reconModelSub;
          //
          var tempPointForm = JSON.parse(JSON.stringify(this.pointForm));
          if (tempPointForm.reconTypeId === 1) {
            tempPointForm.meterPointInfoRequest = this.meterForm;
            tempPointForm.meterPointInfoRequest.meterTypeId = this.pointForm.meterTypeId;
            delete tempPointForm.meterPointInfo;
          } else {
            delete tempPointForm.meterPointInfo;
            delete tempPointForm.meterPointInfoRequest;
          }
          if (tempPointForm.pointVisibleLight) {
            tempPointForm.pointVisibleLightRequest =
              tempPointForm.pointVisibleLight;
          }
          if (
            tempPointForm.pointVisibleLightRequest &&
            tempPointForm.pointVisibleLightRequest.id
          ) {
            //
          } else {
            delete tempPointForm.pointVisibleLightRequest.id;
          }
          delete tempPointForm.pointVisibleLight;
          delete tempPointForm.reconModelSub;
          //
          if (this.isEdit) {
            pointsUpdate(
              // this.pointForm,
              tempPointForm,
              this.data.point.id.substring(6, this.data.point.id.length)
            )
              .then(response => {
                var deviceName = "";
                for (let i = 0; i < this.deviceList.length; i++) {
                  if (this.deviceList[i].id === this.pointForm.deviceId) {
                    deviceName = this.deviceList[i].name;
                  }
                }

                this.setOperationLogs(
                  "修改-" +
                    deviceName +
                    "-巡检点位设置-" +
                    tempPointForm.displayName
                );
                this.dbTableUpdatePub({
                  table_id: 3
                });
                if (
                  tempPointForm.x != this.historyData.x ||
                  tempPointForm.y != this.historyData.y ||
                  tempPointForm.z != this.historyData.z
                ) {
                  //
                  let tempWatchPosId = -1;
                  if (
                    tempPointForm.watchPosId === this.historyData.watchPosId
                  ) {
                    //
                  } else {
                    tempWatchPosId = tempPointForm.watchPosId;
                  }
                  //
                  this.pointStatusPub({
                    robotId: parseInt(this.robot_id),
                    id: parseInt(
                      this.data.point.id.substring(6, this.data.point.id.length)
                    ),
                    pointId: parseInt(tempWatchPosId),
                    status: 1
                  });
                }
                //
                this.$message({
                  message: "编辑成功!",
                  type: "success"
                });
                this.$emit("listenToChildEvent", { type: "edit" });
                let self = this;
                this.$emit("change", "click");
                self.dialogVisible = false;
              })
              .catch(() => {});
          } else {
            // pointsAdd(this.pointForm)
            pointsAdd(tempPointForm)
              .then(response => {
                var deviceName = "";
                for (let i = 0; i < this.deviceList.length; i++) {
                  if (this.deviceList[i].id === this.pointForm.deviceId) {
                    deviceName = this.deviceList[i].name;
                  }
                }
                this.setOperationLogs(
                  "新增-" +
                    deviceName +
                    "-巡检点位设置-" +
                    tempPointForm.displayName
                );

                this.dbTableUpdatePub({
                  table_id: 3
                });
                //
                this.pointStatusPub({
                  robotId: parseInt(this.robot_id),
                  id: parseInt(response.pointId),
                  pointId: parseInt(tempPointForm.watchPosId),
                  status: 0
                });
                //
                this.$message({
                  message: "添加成功!",
                  type: "success"
                });
                this.$emit("listenToChildEvent", { type: "add" });
                let self = this;
                this.$emit("change", "click");
                self.dialogVisible = false;
              })
              .catch(() => {});
          }
        }
      });
    },
    getRobotParams(data) {
      robotParams(data)
        .then(response => {
          if (response.list && response.list.length > 0) {
            for (var i = 0, len = response.list.length; i < len; i++) {
              if (response.list[i].name === "ros_websocket_ip") {
                this.rosObj.ip = response.list[i].value;
              }
              if (response.list[i].name === "ros_websocket_port") {
                this.rosObj.port = response.list[i].value;
              }
            }
          }
        })
        .catch(() => {});
    },
    // 添加日志管理
    setOperationLogs(content) {
      var parm = {
        content: content,
        deviceId: localStorage.getItem("ydRobot_device_id"),
        type: 0
      };
      postOperationLogs(parm)
        .then(response => {})
        .catch(() => {});
    }
  }
};
</script>

<style>
.PointsEdit {
  /*  */
}
.PointsEdit .el-dialog-redefine {
  width: 68%;
  height: 78%;
  /* margin-top: 10vh !important; */
  /* min-height: 600px; */
}
.PointsEdit .el-dialog__header {
  padding: 0;
  background: linear-gradient(
    rgb(227, 242, 238),
    rgb(202, 231, 238)
  ); /* 标准的语法 */
}
.PointsEdit .el-dialog__header .el-dialog__title {
  line-height: 27px;
  font-size: 14px;
  color: #202123;
  padding: 0 6px;
}
.PointsEdit .el-dialog__header .el-dialog__headerbtn {
  width: 23px;
  height: 23px;
  top: 2px;
  right: 5px;
  font-size: 18px;
  border-radius: 3px;
  border: 1px solid rgb(177, 211, 162);
}
.PointsEdit .el-dialog__body {
  height: calc(100% - 27px);
  padding: 3px;
  background-color: rgb(227, 242, 238);
}
.PointsEdit .outside-border {
  width: 100%;
  height: 100%;
  padding: 6px 8px;
  border: 1px solid rgb(194, 221, 228);
  background-color: #ffffff;
}
.PointsEdit .data-area {
  position: relative;
  width: 100%;
  height: calc(100% - 50px);
  border: 1px solid rgb(202, 231, 238);
}

.PointsEdit .el-tabs-redefine {
  width: 100%;
  height: 100%;
  display: flex;
  flex-flow: column;
}

.PointsEdit .el-tabs__header {
  box-sizing: border-box;
  background: linear-gradient(
    rgb(227, 242, 238),
    rgb(202, 231, 238)
  ); /* 标准的语法 */
}

.PointsEdit .el-tabs--border-card {
  border: none;
}

.PointsEdit .el-tabs--border-card > .el-tabs__content {
  flex-grow: 1;
  padding: 8px 8px 8px 8px;
}

.PointsEdit .el-tabs--border-card > .el-tabs__header .el-tabs__item {
  height: 30px;
  margin: 0px 3px 0px 3px;
  line-height: 30px;
  border: 1px solid #ccc;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  color: #000;
}

.PointsEdit .el-tabs--border-card > .el-tabs__header .el-tabs__item.is-active {
  color: rgb(16, 156, 180);
  border: 1px solid rgb(16, 156, 180);
  border-bottom: none;
}

.PointsEdit .el-tab-pane {
  width: 100%;
  height: 100%;
}

.PointsEdit .tab-custom-area {
  width: 100%;
  height: 100%;
  display: flex;
  flex-flow: column;
}

.PointsEdit .conditions-area {
  width: 100%;
  height: auto;
  border: 1px solid rgb(186, 232, 247);
  padding-top: 16px;
  padding-right: 16px;
  overflow: auto;
}
.PointsEdit .el-form-item--mini.el-form-item {
  margin-top: 0;
  margin-bottom: 16px;
}
</style>